package demo1;

public class TestAnimal {
    //通过参数向上转型
/*    public static void eat(Animal animal){
        animal.eat();
    }
    //通过返回值向上转型
    public static Animal getclass(String name){
        if(name.equals("多乐")){
            return new Dog("多乐",3);
        }else{
            return null;
        }
    }*/
    public static void main(String[] args) {
        //直接赋值向上转型
        Animal animal=new Dog("多乐",3);
        if(animal instanceof Dog){
            Dog dog=(Dog)animal;
            dog.bark();
            dog.eat();
        }

        if(animal instanceof Cat){
            Cat cat=(Cat)animal;
            cat.eat();
            cat.mem();
        }


        /*eat(animal);
        Animal animal1 = getclass("多乐");
        System.out.println(animal1.getName());*/
    }
}
